package com.ttech.twitter.socket;

import com.ttech.twitter.stream.TweetSenderThread;
import org.eclipse.jetty.websocket.WebSocket.OnTextMessage;

public class TwitterWebSocket implements OnTextMessage {

    private Connection connection;

    public TwitterWebSocket() {
    }

    public void onMessage(String data) {
    }

    @Override
    public void onOpen(Connection connection) {
        this.connection = connection;
        TweetSenderThread.users.add(this);
        System.out.println("Client connected. Client count: " + TweetSenderThread.users.size());
    }

    @Override
    public void onClose(int closeCode, String message) {
        TweetSenderThread.users.remove(this);
        System.out.println("Client disconnected. Client count: " + TweetSenderThread.users.size());
    }

    public Connection getConnection() {
        return connection;
    }

    public void setConnection(Connection connection) {
        this.connection = connection;
    }
}
